<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:600px; margin-top: 150px;">
  
  <div class="modal-content">
  
    <div class="modal-header x-breadcrumb clearfix">
    
      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>添加二维码</span></h2>
      <button type="button" class="close" data-dismiss="modal">&times;</button>
    
    </div>
    
    <form class="form-horizontal" method="POST" action="${ctx.host}/qrcodes" data-validate="true">
    
      <input type="hidden" id="barcode" name="value" value="">
    
      <div class="modal-body">
        
        <div class="form-group">
          <label class="control-label col-xs-4">二维码图片:</label>
          <div class="upload-barcode pull-left" style="width: 230px; height: 230px;">
            <button type="button" id="pickBarcode" class="edit-btn fade"><span class='glyphicon glyphicon-repeat' aria-hidden='true'></span>&nbsp;&nbsp;重新上传</button>
            <div id="barcodePreviewList"><img id="barcodePreview" src="${cloud.prod}/${qrcode.value}-qrcode" data-alias="-qrcode" style="width: 230px; height: 230px;"/></div>
            <label id="messageBarcode" class="control-label messageBarcode hide"></label>
          </div>
        </div>
        
        <div class="form-group">
          
        </div>
      
        <div class="form-group">
          <label class="control-label col-xs-4">二维码类型:</label>
          <div class="col-xs-6 pull-left">
            <select name="type" class="form-control" data-validate="required">
              <option></option>
              <c:forEach var="qrcodeType" items="${enums['QrcodeType']}">
                <option value="${qrcodeType}">${qrcodeType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div id="qrcodeName" class="form-group hide">
          <label class="control-label col-xs-4">二维码名称:</label>
          <div class="col-xs-6 pull-left">
            <input type="text" name="name" class="form-control">
          </div>
        </div>
        
        <div id="siteName" class="form-group hide">
          <label class="control-label col-xs-4">门店名称:</label>
          <div class="col-xs-6 pull-left">
            <select name="siteId" class="form-control">
              <option></option>
              <c:forEach var="site" items="${persist.sites}">
                <option value="${site.id}">${site.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
      </div>
    
      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
      
    </form>
  
  </div>
</div>

<script>

  $(function() {
    
    $('select[name="type"]').select2({
      placeholder : '二维码类型',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
    $('select[name="alias"]').select2({
      placeholder : '门店名称',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
    $('select[name="type"]').change(function(e){
      if(e.val == "ON_LINE" || e.val == "GROUP_BLOCK") {
        $("#qrcodeName").removeClass("hide");
        $("#siteName").addClass("hide");
      }else if(e.val == "OFF_LINE") {
        $("#siteName").removeClass("hide");
        $("#qrcodeName").addClass("hide");
      }else{
        $("#qrcodeName").addClass("hide");
        $("#siteName").addClass("hide");
      }
    });
    
  });
  
</script>